:winpos 225 225
:set lines=24
:set columns=120

source $VIMRUNTIME/vimrc_example.vim

"查看输入的命令
set showcmd

"自动检测文件类型
filetype on
set guioptions-=T	"去除工具栏
set guioptions-=m	"去除菜单栏

" 使关联系统剪贴板
set clipboard+=unnamed " set clipboard

"解决菜单乱码
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,gbk,default,latin1
set langmenu=zh_CN.utf-8
set imcmdline
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

"解决consle输出乱码
language messages zh_CN.utf-8

"自动检测文件类型并加载相应的设置，snipMate插件需要打开这个配置选项
filetype plugin indent on

"语法高亮
syntax on

"自动缩进
set autoindent
"设置 Backspace 和 Delete 的灵活程度，backspace=2 则没有任何限制
"设置在哪些模式下使用鼠标功能，mouse=a 表示所有模式
set mouse=a
set backspace=2

"设置超过80字符自动换行
set textwidth=80

"智能对齐方式
set smartindent

"一个tab是4个字符
set tabstop=4

"按一次tab前进4个字符
set softtabstop=4

"用空格代替tab
set expandtab

"设置自动缩进
set ai!

"缩进的字符个数
set cindent shiftwidth=4

"设置折叠模式
set foldcolumn=4

set foldmethod=syntax

"启动时不要自动折叠代码
set foldlevel=100

"显示行号
set number

"打开光标的行列位置显示功能
set ruler

"显示中文引号
set ambiwidth=double

"行高亮
set cursorline

"设置命令行的高度
set cmdheight=1

"高亮搜索的关键字
set hlsearch

"搜索忽略大小写
set ignorecase

"设置命令历史行数
set history=100

"显示TAB健
set list
set listchars=tab:>-,trail:-

"设置VIM状态栏
set laststatus=2
set statusline=
set statusline+=%2*%-3.3n%0*\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%1*%m%r%w%0* " flag 
set statusline+=[
if v:version >= 600
    set statusline+=%{strlen(&ft)?&ft:'none'}, " filetype
    set statusline+=%{&encoding}, " encoding
endif
set statusline+=%{&fileformat}] " file format
if filereadable(expand("$VIM/vimfiles/plugin/vimbuddy.vim"))
    set statusline+=\ %{VimBuddy()} " vim buddy
endif
set statusline+=%= " right align
"set statusline+=%2*0x%-8B\ " current char
set statusline+=0x%-8B\ " current char
set statusline+=%-14.(%l,%c%V%)\ %<%P " offset

"设置路径,多个路径用逗号分隔
set path=.,,

"是否兼容VI，compatible为兼容，nocompatible为不完全兼容
"如果设置为compatible，则tab将不会变成空格
set nocompatible

"缺省不产生备份文件
set nobackup
set nowritebackup

"在输入括号时光标会短暂地跳到与之相匹配的括号处，不影响输入
set showmatch

"正确地处理中文字符的折行和拼接
set formatoptions+=mM

"设定文件浏览器目录为当前目录
set bsdir=buffer

"使PHP识别EOT字符串
hi link phpheredoc string

"允许在有未保存的修改时切换缓冲区
set hidden

"选中一段文字并全文搜索这段文字
vmap <silent> ,/ y/<C-R>=escape(@", '\\/.*$^~[]')<CR><CR>
vmap <silent> ,? y?<C-R>=escape(@", '\\/.*$^~[]')<CR><CR>


"保存文件的格式顺序
set fileformats=unix,dos

"配色（更多的配色见colors目录和
color desert

"设置字体
if has("gui")
    if has("win32")
        "启动时会弹出字体选择框，如果取消，则采用系统默认字体
        "set guifont=*
        "不支持该字体
        "set guifont=YaHei\ Consolas\ Hybrid:h12
        "中文显示变形
        "set guifont=Monaco:h9
        "中文显示变形
        "set guifont=Consolas:h9
        "完美支持中文
        "set guifont=Lucida\ Sans\ Typewriter\ Std:h10
        "中文显示变形
        "set guifont=Bitstream\ Vera\ Sans\ Mono
        "set guifontwide=SimSun:h9
        set guifont=Monaco:h9
        set guifontwide=YaHei\ Consolas\ Hybrid:h9
    else
        set guifont=SimSun:h10
    endif
    "set columns=128 lines=36
endif

"置粘贴模式，这样粘贴过来的程序代码就不会错位了。
set paste

"设置帮助信息
set helplang=cn

"自动保存session和viminfo
"缺省的sessionoptions选项包括：blank,buffers,curdir,folds,help,options,tabpages,winsize
"也就是会话文件会恢复当前编辑环境的空窗口、所有的缓冲区、当前目录、折叠(fold)相关的信息、帮助窗口、所有的选项和映射、所有的标签页(tab)、窗口大小
"set sessionoptions-=curdir
"au VimLeave * mksession! $VIMRUNTIME/Session.vim
"au VimLeave * wviminfo! $VIMRUNTIME/_viminfo
"source $VIMRUNTIME/Session.vim
"rviminfo $VIMRUNTIME/_viminfo

set diffexpr=MyDiff()

function! MyDiff()
    let opt = '-a --binary '
    if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
    if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
    let arg1 = v:fname_in
    if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
    let arg2 = v:fname_new
    if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
    let arg3 = v:fname_out
    if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
    let eq = ''
    if $VIMRUNTIME =~ ' '
        if &sh =~ '\<cmd'
            let cmd = '""' . $VIMRUNTIME . '\diff"'
            let eq = '"'
        else
            let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
        endif
    else
        let cmd = $VIMRUNTIME . '\diff'
    endif
    silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction


"You can obtain the completion dictionary file from:
"http://cvs.php.net/viewvc.cgi/phpdoc/funclist.txt
set dictionary+=$VIM\vimfiles\syntax\funclist.txt

"Use the dictionary completion
set complete-=k complete+=k

"平台判断
function! HasWindows()
  if (has("win32") || has("win95") || has("win64") || has("win16"))
    return 1
  else
    return 0
  endif
endfunction

"取得光标处的匹配
function! GetPatternAtCursor(pat) "{{{
  let col = col('.') - 1
  let line = getline('.')
  let ebeg = -1
  let cont = match(line, a:pat, 0)
  while (ebeg >= 0 || (0 <= cont) && (cont <= col))
    let contn = matchend(line, a:pat, cont)
    if (cont <= col) && (col < contn)
      let ebeg = match(line, a:pat, cont)
      let elen = contn - ebeg
      break
    else
      let cont = match(line, a:pat, contn)
    endif
  endwh
  if ebeg >= 0
    return strpart(line, ebeg, elen)
  else
    return ""
  endif
endfunction

"F2处理行尾的空格以及文件尾部的多余空行
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif

"Remove indenting on empty line
map <F2> :w<CR>:call CleanupBuffer(1)<CR>:noh<CR>

function! CleanupBuffer(keep)
    " Skip binary files
    if (&bin > 0)
        return
    endif
    " Remove spaces and tabs from end of every line, if possible
    silent! %s/\s\+$//ge
    " Save current line number
    let lnum = line(".")
    " number of last line
    let lastline = line("$")
    let n        = lastline
    " while loop
    while (1)
        " content of last line
        let line = getline(n)
        " remove spaces and tab
        if (!empty(line))
            break
        endif
        let n = n - 1
    endwhile
    " Delete all empty lines at the end of file
    let start = n+1+a:keep
    if (start < lastline)
        execute n+1+a:keep . "," . lastline . "d"
    endif
    " after clean spaces and tabs, jump back
    exec "normal " . lnum . "G"
endfunction

"PHP语法检查
function! CheckPHPSyntax()
	setlocal makeprg=\"D:\Program\ Files\PHP5.2.6\php.exe\"\ -l\ -n\ -d\ html_errors=off
	setlocal shellpipe=>
	setlocal errorformat=%m\ in\ %f\ on\ line\ %l
	make %
endfunction

map <F4> :call CheckPHPSyntax()<CR>

"netrw设置（自带目录树插件）
let g:netrw_winsize=30
let g:netrw_liststyle=1
let g:netrw_timefmt='%Y-%m-%d %H:%M:%S'
nmap <silent> <C-F7> :Sexplore!<cr>

"F6打开或关闭nerd_tree和taglist
"由于nerd_tree和taglist采用了trinity插件打开
"所以具体的设置以trinity.vim为准
nmap <F6>  :TrinityToggleTagListAndNERDTree<CR>

"F7单独切换打开nerd_tree（nerd_tree插件）
let g:NERDChristmasTree = 1              "色彩显示
let g:NERDTreeShowHidden = 1             "显示隐藏文件
let g:NERDTreeWinPos = 'left'            "窗口显示位置
let g:NERDTreeHighlightCursorline = 0    "高亮当前行
nmap <F7>  :TrinityToggleNERDTree<CR>    "始终在右边显示

"F8单独切换打开taglist（taglist插件）
if HasWindows() == 1                    "设定Windows系统中ctags程序的位置
    let g:Tlist_Ctags_Cmd = $VIMRUNTIME.'\ctags'
else
    let g:Tlist_Ctags_Cmd = '/usr/bin/ctags'
endif
"let g:Tlist_Sort_Type = 'name'          "以名称顺序排序，默认以位置顺序(order)
let g:Tlist_Show_One_File = 1           "不同时显示多个文件的tag，只显示当前文件的
let g:Tlist_Exit_OnlyWindow = 1         "如果taglist窗口是最后一个窗口，则退出vim
lef g:Tlist_File_Fold_Auto_Close = 1    "当光标不在编辑文件里面的时候全部折叠
let g:Tlist_Use_Right_Window = 1        "在右侧窗口中显示taglist窗口
let g:Tlist_Enable_Fold_Column = 1      "显示折叠边栏
nmap <F8>  :TrinityToggleTagList<CR>

"F11查看打开的文件列表（bufexplorer插件）
let g:bufExplorerDefaultHelp = 1
let g:bufExplorerDetailedHelp = 0
nmap <F11> :BufExplorer <CR>

"F12生成/更新tags文件
set tags=tags;
set autochdir
function! UpdateTagsFile()
    silent !ctags -R --fields=+ianS --extra=+q
endfunction
nmap <F12> :call UpdateTagsFile()<CR>

"Ctrl + F12删除tags文件
function! DeleteTagsFile()
    "Linux下的删除方法
    "silent !rm tags
    "Windows下的删除方法
    silent !del /F /Q tags
endfunction
nmap <C-F12> :call DeleteTagsFile()<CR>